package com.zoe.config;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.stereotype.Component;

/**
 * @Author Zoe
 * @Date: 2020/12/14
 * @Description beanFactory的后置处理器；
 *              在所有BeanFactory标准初始化之后调用,来定制和修改BeanFactory的内容
 *              所有的Bean定义已经保存到BeanFactory,但是Bean的实例还没有被创建
 */

@Component
public class MyBeanFactoryPostProcessor implements BeanFactoryPostProcessor {

    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
        System.out.println("MyBeanFactoryPostProcessor被加载");
        for (String beanDefinitionName : beanFactory.getBeanDefinitionNames()) {
            System.out.println(beanDefinitionName);
        }
        System.out.println("bean的条数：" + beanFactory.getBeanDefinitionCount());
        System.out.println("");
    }
}
